<?php

namespace App\Models;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;
#费用表模型
class Fee extends Model
{
    #主键
    public $primaryKey='pid';

	/**
	 * 表明模型是否应该被打上时间戳
	 *
	 * @var bool
	 */
	public $timestamps = false;
	#关联关系：('Model','foreign_key','other_key')

	#获取拥有此经费的项目
	public function project(){
		return $this->belongsTo('App\Models\Project_info','pid','pid');
	}



	#初始化一张经费预算单
	public static function init($pid){
		$fees=new Fee;
		$fees->pid=$pid;
		$fees->fee1=0;
		$fees->fee2=0;
		$fees->fee3=0;
		$fees->fee4=0;
		$fees->fee5=0;
		$fees->save();
		return $fees;
	}

	#修改经费预算
	public static function modify(Request $request,$pid){
		$fees=Fee::find($pid);
		$fees->fee1=$request->input('fee1');
		$fees->fee2=$request->input('fee2');
		$fees->fee3=$request->input('fee3');
		$fees->fee4=$request->input('fee4');
		$fees->fee5=$request->input('fee5');
		$fees->save();
		return true;
	}
}
